﻿Imports Microsoft.VisualBasic
Imports System.Data.OleDb
Imports System.Data

Public Class clsUser
  
    Public Function UpdateDatasetUser(ByVal dsData As System.Data.DataSet, ByRef Transaction As OleDbTransaction) As System.Int32

        Dim cmdAdd As OleDbCommand = New OleDbCommand
        Dim cmdEdit As OleDbCommand = New OleDbCommand
        Dim cmdDelete As OleDbCommand = New OleDbCommand
        Dim daUpdate As OleDbDataAdapter = New OleDbDataAdapter

        Dim intResult As System.Int32


        With cmdAdd
            .Connection = Transaction.Connection
            .Transaction = Transaction
            .CommandText = "INSERT INTO TEST (USERID,USERNAME,PASSWORD) VALUES (@USERID,@USERNAME,@PASSWORD)"
            .CommandType = CommandType.Text
            .Parameters.Add(New System.Data.OleDb.OleDbParameter("@USERID", OleDbType.VarChar, 0, ParameterDirection.Input, True, CByte(0), CByte(0), "USERID", DataRowVersion.Current, Nothing))
            .Parameters.Add(New System.Data.OleDb.OleDbParameter("@USERNAME", OleDbType.VarChar, 0, ParameterDirection.Input, True, CByte(0), CByte(0), "USERNAME", DataRowVersion.Current, Nothing))
            .Parameters.Add(New System.Data.OleDb.OleDbParameter("@PASSWORD", OleDbType.VarChar, 0, ParameterDirection.Input, True, CByte(0), CByte(0), "PASSWORD", DataRowVersion.Current, Nothing))

        End With

        With cmdEdit
            .Connection = Transaction.Connection
            .Transaction = Transaction
            .CommandText = "UPDATE TEST SET " _
             & "USERID=@USERID,USERNAME=@USERNAME,PASSWORD=@PASSWORD " _
             & "WHERE USERID=@USERID"
            .CommandType = CommandType.Text
            .Parameters.Add(New System.Data.OleDb.OleDbParameter("@USERID", OleDbType.VarChar, 0, ParameterDirection.Input, True, CByte(0), CByte(0), "USERID", DataRowVersion.Current, Nothing))
            .Parameters.Add(New System.Data.OleDb.OleDbParameter("@USERNAME", OleDbType.VarChar, 0, ParameterDirection.Input, True, CByte(0), CByte(0), "USERNAME", DataRowVersion.Current, Nothing))
            .Parameters.Add(New System.Data.OleDb.OleDbParameter("@PASSWORD", OleDbType.VarChar, 0, ParameterDirection.Input, True, CByte(0), CByte(0), "PASSWORD", DataRowVersion.Current, Nothing))
        End With

        With cmdDelete
            .Connection = Transaction.Connection
            .Transaction = Transaction
            .CommandText = "DELETE * FROM TEST WHERE USERID=@USERID"
            .CommandType = CommandType.Text
            .Parameters.Add(New System.Data.OleDb.OleDbParameter("@USERID", OleDbType.VarChar, 0, ParameterDirection.Input, True, CByte(0), CByte(0), "USERID", DataRowVersion.Current, Nothing))
        End With

        With daUpdate
            .InsertCommand = cmdAdd
            .UpdateCommand = cmdEdit
            .DeleteCommand = cmdDelete
        End With
        intResult = daUpdate.Update(dsData, "TEST")
        daUpdate.Dispose()
        cmdAdd.Dispose()
        cmdEdit.Dispose()
        cmdDelete.Dispose()
        daUpdate = Nothing
        cmdEdit = Nothing
        cmdEdit = Nothing
        cmdDelete = Nothing
        Return intResult
    End Function


End Class




